<?php
namespace app\api\controller;
use app\api\controller\BaseController;
use app\common\errcode\ApiErrCode;
use app\common\errcode\ApiErrMsg;
use think\Loader;

class IndexController extends BaseController
{
    protected $indexModel;

    public function __construct()
    {
        parent::__construct();
        $this->indexModel = new \app\api\model\IndexModel();
    }

    /**
     * @param string    $method 工具列表:tool;分类列表:cat
     * @param int       $catid  分类id
     */
    public function index()
    {
        try {
            if($this->request->isPost()){
                $data = $this->request->post();
                $validate = Loader::validate('Index');
                $check = $validate->scene('list')->check($data);
                if(!$check){
                    return $this->jsonJump(ApiErrCode::PARAM_ERROR,ApiErrMsg::PARAM_ERROR.','.$validate->getError());  
                }
                return $this->jsonJump(ApiErrCode::SUCCESS,ApiErrMsg::SUCCESS,$this->indexModel->list($data));    
            }    
        } catch (\Exception $e) {
            \app\common\model\CommonModel::recordLog($this->userid,'abnormal',date('Y-m-d H:i:s'),'warning',$e->getMessage());
            return $this->jsonJump(ApiErrCode::SYSTEM_ERROR,ApiErrMsg::SYSTEM_ERROR . ',错误信息:'. $e->getMessage());
        }    
    }
}